package com.caine.proxy.service.impl;

import com.caine.proxy.service.ProxyService;
import com.caine.proxy.service.SpringContextUtil;
import com.caine.proxy.vo.ParamVO;
import org.springframework.stereotype.Service;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

@Service
public class SpringProxyServiceImpl implements ProxyService {

    @Override
    public void process() throws Exception {
        Class<?> ruleClass = Class.forName("com.caine.proxy.service.impl.DoSomeThingServiceImpl");
        DoSomeThingServiceImpl service = (DoSomeThingServiceImpl)SpringContextUtil.getBeanByClass(ruleClass);
        Class<?>[] methodParamTypes = new Class[1];
        methodParamTypes[0] = Class.forName("com.caine.proxy.vo.ParamVO");
        Method method = ruleClass.getMethod("doAnyThing", methodParamTypes);
        ParamVO vo = new ParamVO();
        vo.setMsg("大锤八十!");
        Object result = ReflectionUtils.invokeMethod(method,service,new Object[]{vo});
    }
}
